import { createSvg, _defs, _rect, _circle, _patternId } from '../svg.js'
// 格子图案
// fill="url(#shape-chequer)"
export const _chequer = (options) => {
    let {
        name,
        id = 'shape-chequer',
        r = 10,
        color1 = 'red',
        color2 = 'green',
        borderRadius1 = 1,
        borderRadius2 = 1,
    } = options
    id = _patternId(id, name)
    let rect1 = _rect(
        [[0, 0],
        [r, r]]
        ,
        {
            fill: color1,
            rx: borderRadius1,
            ry: borderRadius1,
        }
    )
    let rect2 = _rect([[r, r],
    [r * 2, r * 2]],



        {
            fill: color2,
            rx: borderRadius2,
            ry: borderRadius2,
        }
    )

    let chequer = createSvg(
        'pattern', {
        id,
        x: 0,
        y: 0,
        width: r * 2,
        height: r * 2,
        patternUnits: 'userSpaceOnUse',
    },
        {},
        [rect1, rect2]
    )
    let defs = _defs(chequer)
    return defs
}


// 点点
export const _dot = (options) => {
    let {
        name,
        r = 5,
        id = 'dot'
    } = options
    id = _patternId(id, name)
    let dots = [_circle({ o: [r, r], r }, {
        fill: 'red'
    }), _circle({ o: [3 * r, 3 * r], r }, {
        fill: 'green'
    })]

    let chequer = createSvg(
        'pattern', {
        id,
        x: 0,
        y: 0,
        width: r * 4,
        height: r * 4,
        patternUnits: 'userSpaceOnUse',
    },
        {},
        dots
    )

    let defs = _defs(chequer)
    return defs
}